package com.ysjy.course.config;

import com.ysjy.course.mapper.OrderMapper;
import lombok.extern.slf4j.Slf4j;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.scheduling.annotation.EnableScheduling;
import org.springframework.scheduling.annotation.Scheduled;
import org.springframework.stereotype.Component;
import org.springframework.transaction.annotation.Transactional;

import java.util.*;
import java.util.stream.Collectors;

@Transactional
@Component
@Slf4j
@EnableScheduling
public class TimerTask {

    @Autowired
    private OrderMapper orderMapper;

    //每5分钟执行
    @Scheduled(fixedRate = 1000 * 5 * 60)
    public void courseTimeTask() {
        //已失效的订单（72小时未支付）
        orderMapper.deleteInvalid();
    }
}
